<?php
/**
 * WorkPlace Model Class File
 *
 * @package
 * @author
 */

/**
 * This is the model class for table "workplace".
 *
 * The followings are the available columns in table 'workplace':
 * @property integer $id
 * @property integer $companyId
 * @property integer $name
 * @property string $description
 *
 * @package
 * @author
 */
class WorkPlace extends MyModel
{
    // {{{ *** Members ***

    /**
     * List of fields composing the record name (separated by ;)
     * @var string
     */
    var $nameFields = "name;id";

    /**
     * Name format string (e.g. '{1} (#{2})' 
     * @var string
     */
    var $nameFormat = "{1} (#{2})";
    
    /**
     * Does this model use record revisions?
     * @var bool
     */
    var $usesRevision   = false;

    /**
     * Revision number of current record
     * @var int
     */
    var $recordRevision;

    /**
     * Does this model use logging?
     * @var bool
     */
    var $usesLog        = false;

    // }}} 
    // {{{ *** Methods ***
    // {{{ model
    /**
     * Returns the static model of the specified AR class.
     * @return WorkPlace the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    } // }}} 
    // {{{ tableName
    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{WorkPlace}}';
    } // }}} 
    // {{{ rules
    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name', 'required'),
            array('companyId', 'numerical', 'integerOnly'=>true),
            array('name','length','max'=>255),
            array('companyId, description', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, companyId, name, description', 'safe', 'on'=>'search'),
        );
    } // }}} 
    // {{{ beforeSave
    public function beforeSave()
    {
        if(parent::beforeSave())
        {
            $this->companyId = Yii::app()->user->companyId;
            return true;
        }
        else
            return false;
    } // }}} 
    // {{{ relations
    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    } // }}} 
    // {{{ attributeLabels
    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => Yii::t('site','ID'),
            'companyId' => Yii::t('site','Company'),
            'name' => Yii::t('site','Name'),
            'description' => Yii::t('site','Description'),
        );
    } // }}} 
    // {{{ scopes
    public function scopes()
    {
        return array(
            'liveUser'=>array(
                'condition'=>'t.companyId='.Yii::app()->user->companyId,
            ),
        );
    } // }}}
    // {{{ search
    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
                $criteria->compare('companyId',Yii::app()->user->companyId);		
                $criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
        return new CActiveDataProvider(get_class($this), array('criteria'=>$criteria));
    } // }}} 
    // }}} 
}

/* vim: set ai sw=4 sts=4 et fdm=marker fdc=4 */ 
?>
